/*-----------------------------------------------------------------------------------------------
// Copyright (C) 2016 华跃博弈科技有限公司 
//
// 文件名：        MatMenuRepository.cs
// 文件功能描述：   菜单持久化类
//
// 
// 创建标识：       庞永飞  2016-04-24
//
// 修改标识：
// 修改描述：
//
// 备注：	
// 				
//-----------------------------------------------------------------------------------------------*/

using HYBY.Task.DataEntity.Admin;
using HYBY.Task.Repository.IRepository;

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;



namespace HYBY.Task.Repository.Admin {
    
    public class MatMenuRepository : BaseRepository<MatMenuEntity>, IMatMenuRepository {

        #region 常量

        private const string CONST_GetMenus = "MAT_PLAT#GetMenus";
        private const String CONST_GetChildMenus = "MAT_PLAT#GetChildMenus";
        private const String CONST_SaveMenu = "MAT_PLAT#SaveMenu";
        private const String CONST_DeleteMenu = "MAT_PLAT#DeleteMenu";
        private const String CONST_GetMat_MenuPaged = "MAT_PLAT#GetMat_MenuPaged";
        private const String CONST_GetMat_MenuPagedCount = "MAT_PLAT#GetMat_MenuRecordCount";  
                                                     

        #endregion

        #region 构造器

        public MatMenuRepository() {

        }

        #endregion

        #region 公共方法

        public List<MatMenuEntity> GetMenus() {
            return Query<MatMenuEntity>(CONST_GetMenus).ToList();
        }

        public List<MatMenuEntity> GetMenus(Guid parentID) {
            return Query<MatMenuEntity>(CONST_GetChildMenus, new { PrentMenuID = parentID }).ToList();
        }

        public override bool Save(MatMenuEntity entity) {
            return Execute(CONST_SaveMenu, entity) > 0;
        }

        public override bool Delete(MatMenuEntity entity) {
            return Execute(CONST_DeleteMenu, new { Mat_Menu_ID = entity.Mat_Menu_ID }) > 0;
        }

        /// <summary>
        /// 分页方式返回
        /// </summary>
        /// <param name="PageIndex">页面索引</param>
        /// <param name="PageSize">页面大小</param>
        /// <param name="RecordCount">总记录数</param>
        /// <returns></returns>
        public List<MatMenuEntity> GetMat_Menus(String searchKey,int pageIndex, int pageSize, out int recordCount) {
            //设置Velocity 模板引擎参数值
            Dictionary<String, object> TemplateParams = new Dictionary<string, object>{
            {"Mat_Menu_Name", String.IsNullOrEmpty(searchKey)?String.Empty:searchKey}
            };

           recordCount = Query<Int32>(CONST_GetMat_MenuPagedCount,
                TemplateParams, new { Mat_Menu_Name =searchKey}).FirstOrDefault();            
            return Query<MatMenuEntity>(CONST_GetMat_MenuPaged,
                TemplateParams, new { PageIndex = pageIndex, PageSize = pageSize, Mat_Menu_Name=searchKey }
               ).ToList();
        }
        #endregion



    }
}